package com.bs.repository;

import com.bs.domain.AlertType;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by wujian
 * Date: 2017-12-08
 * Time: 15:02
 */
public interface AlertTypeRepository extends JpaRepository<AlertType, Long>, JpaSpecificationExecutor<AlertType> {

    @Query(value = "select s.ALERT_ID,s.USER_ID,u.USER_MAIL,u.USER_PHONE,t.ALERT_MSG, s.MSG_TYPE, t.ALERT_DESC, t.ALERT_LINK " +
        "from alert_sub s,alert_type t,alert_user u " +
        "where s.ALERT_ID=t.ALERT_ID " +
        "and s.USER_ID=u.USER_ID " +
        "and t.ALERT_NAME=?1 " +
        "and s.PARTITION_ID=?2 " +
        "and (s.MODULE_NAME=?3 OR s.MODULE_NAME='ALL' OR s.MODULE_NAME=SUBSTRING(?3, 1,2)) ", nativeQuery = true)
    List<Object[]> findAlertInfo(String alertName, String partitionId, String moduleName);

}
